/*
 * @javascript 验证小全 (*^__^*)
 * @author liuyang
 */

function alertMsg(e,msg){
	var msgDiv = document.createElement("div");
	msgDiv.id =  "msgDiv";
	document.body.appendChild(msgDiv);
	var offset = $(e).offset();
	var div = $("#msgDiv");
	div.empty();
	div.append(msg);
	div.css("border","1px solid black").width("150px").css("position","absolute").css("background-color","red").css("color","white").css("z-index","20");
	div.css("left",offset.left+"px").css("top",offset.top+div.height()+"px").css("display","none");
	div.fadeIn("slow");
	setTimeout(function(){div.fadeOut("slow");},2000);
}

function setLength(e,lng) 
{
	if(e.value.length>lng)
	{
		e.value="";
		alertMsg(e,"不能超过"+lng+"个字符");
	}
}
function onlyCN(e){
	var reg = /[^\u4E00-\u9FA5]/gi;
	if(reg.test(e.value)){
		e.value = "";
		alertMsg(e,"只能输入中文");
	}
}
function onlyNumCN(e){
	var reg = /[^\u4E00-\u9FA5-0-9]/gi;
	if(reg.test(e.value)){
		e.value = "";
		alertMsg(e,"只能输入中文与数字");
	}
}
function onlyEN(e){
	var reg = /[^a-z]/gi;
	if(reg.test(e.value)){
		e.value = "";
		alertMsg(e,"只能输入英文");
	}
}
function onlyNum(e){
	var reg = /[^0-9]/gi;
	if(reg.test(e.value)){
		e.value = "";
		alertMsg(e,"只能输入数字");
	}
}
function setNumLength(e,lng){
	var reg = /[^0-9]/gi;
	if(reg.test(e.value)){
		e.value = "";
		alertMsg(e,"只能输入数字");
	}else if(e.value.length>lng){
		e.value="";
		alertMsg(e,"不能超过"+lng+"个字符");
	}
}
function onlyNumEN(e){
	var reg = /[\W]/gi;
	if(reg.test(e.value)){
		e.value = "";
		alertMsg(e,"只能输入数字与英文");
	}
}
function setEmail(e){
	var reg = /^(?:\w+\.?)*\w+@(?:\w+\.?)*\w+$/;
	if(reg.test(e.value)==false){
		e.value = "";
		alertMsg(e,"邮箱格式有误");
	}
}
function getDay(e){
	var reg =  /^(\d{4})-(\d{2})-(\d{2})$/; 
	if(reg.test(e.value)==false){
		e.value = "";
		alertMsg(e,"请单击表框选择日期");
	}
}
function testDay(sd,ed){
	alert(1);
	var sd = $("input[name='"+sd+"']");
	var ed = $("input[name='"+ed+"']");
	$.each(sd,function(i,n){
		sd = n.value.replace(/-/g,"/");
	});
	$.each(ed,function(i,n){
		ed = n.value.replace(/-/g,"/");
	});
	alert(1);
	if(Date.parse(sd)-Date.parse(ed)>0){   
		alert("开始时间不能大于结束时间");
		return false;
	}  
}

function checkEmpty(number){
	var targetForm = document.forms[number]
	for(i=0;i<targetForm.length;i++){
		if(targetForm.elements[i].value==""){
		alert("表单信息不能为空");
		return false;
		}
	}	
}
function fuck(e) {
	if((e.value.indexOf ("fuck") == 0)||(e.value.indexOf ("") == 0)){
		e.value = "";
		e.focus();
		alertMsg(e,"");
	}
}	

function sends(href,datas)  
{  
	var vl = href+"?pageInfo.nowPage="+datas;
	window.location.href = vl;	
}



(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);
$(function(){
	var input = $(":input[type='text']");
	$.each(input,function(i,n){
		$(n).css("width","150px").css("background","#FFFFFF").css("border","1px solid #000");
	})
	
	
	var a = $("td a");
	$.each(a,function(i,n){
		$(n).css("backgroundPosition","-20px 35px" )
		.mouseover(function(){
			$(n).stop().animate("backgroundPosition","-20px 94px","duration","500")
		})
		.mouseout(function(){
			$(n).stop().animate("backgroundPosition","40px 35px","duration","200", "complete",function(){
				$(n).css("backgroundPosition","-20px 35px")
			})
		})
	});
})
$(function(){
	$("td a").css( {backgroundPosition: "-20px 35px"} )
	.mouseover(function(){
		$(this).stop().animate({backgroundPosition:"(-20px 94px)"}, {duration:500})
	})
	.mouseout(function(){
		$(this).stop().animate({backgroundPosition:"(40px 35px)"}, {duration:200, complete:function(){
			$(this).css({backgroundPosition: "-20px 35px"})
		}})
	})
});
$(function(){
	var trbg;
	var tdbg;
	$("tr[class!='top']").hover(
			function(){
				trbg = this.style.background;
				this.style.background = "white";
				},
			function(){
					this.style.background = trbg;
				});
})
$(function(){
	$(":input").focus(function(){
		if (this.type != "submit" && this.type != "button") {
			$(this).css({
				background: "#8080ff",
				color: "white"
			});
		}
	});
	$(":input").blur(function(){
		if (this.type != "submit" && this.type != "button") {
			$(this).css({
				background: "white",
				color: "black"
			});
		}
	});
	$(":input").change(function(){
		if(this.type == "radio" || this.type == "checkbox"){
			if(this.checked){
				var box = $(":"+this.type+"[name='"+this.name+"']");
				$.each(box,function(i,n){
					$(n).removeAttr("style");
				});
			}
		}else if(this.type != "submit" && this.type != "button"){
			if(this.value != ""){
			$(this).removeAttr("style");
			}
		}
	});
	$(":submit").click(function(){ 
		var form = this.form;
		var result = 0;
		$.each(form,function(i,n){
			if(n.type == "radio" || n.type == "checkbox"){
				var radios = $(":"+n.type+"[name='" + n.name + "']");
					var r = testCheck(radios);
					if(!r){
						result++;
						$(n).css({border:"solid 1px red"});
					}
			 }else if(n.value == ""){
				result++;
				$(n).css({border:"solid 1px red"});
			}
		});
		
		function testCheck(es){
			var length = 0;
			$.each(es,function(i,n){
				if(n.checked == true){
					length++;
				}
				else{
				}
			});
			if(length>0){
				return true;
			}else{
				
				return false;
			}
		}
		if(result>0){
			var etable = document.createElement("div");
			var etitle = document.createElement("div");
			var emsg = document.createElement("div");
			etable.id = "etable";
			etitle.id = "etitle";
			emsg.id = "emsg";
			
			document.body.appendChild(etable);
			etable.appendChild(etitle);
			etable.appendChild(emsg);
			
			var etable = $("#etable");
			var etitle = $("#etitle");
			var emsg = $("#emsg");
			etitle.empty();
			emsg.empty();
			etable.css({border:"solid 1px #8080ff",width:"400px",display:"none","z-index":"99"});
			etitle.css({background:"#8080ff",height:"20px",width:"400px","text-align":"center",color:"white","z-index":"99"});
			emsg.css({width:"390px","font-size":"14px","padding":"5px",color:"red","text-align":"center","z-index":"99"});
			etitle.append(" - 友情提示 - ");
			emsg.append("<fieldset>"+
						"<legend style='color:#8080ff'>您的操作有误,请根据提示从新操作:</legend><p>"+
						"请填写完您的数据"+
						"<ul id='sec'></ul>"+
						"</p></fieldset");
			var  k = 4
			etable.fadeIn("slow",function(){
				var sec = $("#sec");
				
				setTimeout(function(){
					etable.fadeOut("slow");
				},4000)
				
			});
					
			return false;
		}else{
			return true;
		}
	})
})


$(function(){
	var sub = $(":submit");
	var btn = $(":button");
	var rst = $(":reset");
	$.each(sub,function(i,n){
		$(n).css("text-align","center").css("vertical-align","text-top")
		.css("width","80px").css("height","33px").css("border","0px #000")
		.css({background:"url(images/buttons.png) no-repeat top"}).css("font-weight","bolder");
	});
	$.each(btn,function(i,n){
		$(n).css("text-align","center").css("vertical-align","text-top")
		.css("width","80px").css("height","33px").css("border","0px #000")
		.css({background:"url(images/buttons.png) no-repeat top"}).css("font-weight","bolder");
	});
	$.each(rst,function(i,n){
		$(n).css("text-align","center").css("vertical-align","text-top")
		.css("width","80px").css("height","33px").css("border","0px #000")
		.css({background:"url(images/buttons.png) no-repeat top"}).css("font-weight","bolder");
	});
})